package com.flyoil.petromp.adapter.adapter_order;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.flyoil.petromp.R;
import com.flyoil.petromp.base.MyBaseAdapter;
import com.flyoil.petromp.entity.entity_order.OrderSignatureEntity;

/**
 * Created by Administrator on 2017/10/27.
 * 工单详情界面签字列表item的适配器
 */

public class ItemOrderMessageSignatureAdapter extends MyBaseAdapter<OrderSignatureEntity> {
    public ItemOrderMessageSignatureAdapter(Context context) {
        super(context);
    }

    @Override
    public View setView(int position, View convertView, ViewGroup parent) {
        ViewHoder viewHoder;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_order_message_signature_layout, null);
            viewHoder = new ViewHoder(convertView);
            convertView.setTag(viewHoder);
        } else {
            viewHoder = (ViewHoder) convertView.getTag();
        }
        final OrderSignatureEntity entity = (OrderSignatureEntity) getItem(position);
        viewHoder.tv_name.setText(entity.getUsername());
        if (entity.getUsername() != null && entity.getUsername().length() > 0) {
            viewHoder.tv_name_first.setText(entity.getUsername().substring(0, 1));
        }
        viewHoder.tv_operation.setText("操作：" + entity.getOperation());
        if(entity.getOpinion()!=null&&entity.getOpinion().length()>0){
            viewHoder.tv_remark.setVisibility(View.VISIBLE);
        }else {
            viewHoder.tv_remark.setVisibility(View.GONE);
        }
        viewHoder.tv_remark.setText(entity.getOpinion());
        viewHoder.tv_time.setText("批准于 " + entity.getAppliedTimeLabel());
        viewHoder.tv_nodeLabel.setText("节点：" + entity.getSequence());
        if (entity.isShowck()) {
            viewHoder.line_botton.setVisibility(View.VISIBLE);
            viewHoder.img_select.setImageResource(R.mipmap.back_gray_top_icon);
        } else {
            viewHoder.line_botton.setVisibility(View.GONE);
            viewHoder.img_select.setImageResource(R.mipmap.back_gray_botton_icon);
        }
        viewHoder.img_select.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                entity.setShowck(!entity.isShowck());
                notifyDataSetChanged();
            }
        });
        if (position == data.size() - 1)
            viewHoder.view_line.setVisibility(View.GONE);
        else
            viewHoder.view_line.setVisibility(View.VISIBLE);


        return convertView;
    }

    private class ViewHoder {
        private TextView tv_name_first;
        private TextView tv_name;
        private TextView tv_remark;
        private TextView tv_time;
        private TextView tv_nodeLabel;
        private TextView tv_operation;
        private LinearLayout line_botton;
        private ImageView img_select;
        private View view_line;

        @SuppressLint("WrongViewCast")
        public ViewHoder(View view) {
            this.tv_name = view.findViewById(R.id.tv_item_order_message_signature_name);
            this.tv_name_first = view.findViewById(R.id.tv_item_order_message_signature_name_frist);
            this.line_botton = view.findViewById(R.id.line_item_order_message_signature_botton);
            this.img_select = view.findViewById(R.id.img_item_order_message_signature_select);
            this.view_line = view.findViewById(R.id.line_item_order_message_signature);
            this.tv_remark = view.findViewById(R.id.tv_item_order_message_signature_remark);
            this.tv_time = view.findViewById(R.id.tv_item_order_message_signature_time);
            this.tv_nodeLabel = view.findViewById(R.id.tv_item_order_message_signature_nodeLabel);
            this.tv_operation = view.findViewById(R.id.tv_item_order_message_signature_operation);
        }
    }
}
